package com.tanhua.server.controller;

import com.tanhua.model.vo.ErrorResult;
import com.tanhua.server.Exception.BusinessException;
import com.tanhua.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class LoginController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public ResponseEntity login(@RequestBody Map map) {
        String phone = (String) map.get("phone");
        userService.sendMsg(phone);
        //return ResponseEntity.status(500).body("出错了");
        return ResponseEntity.ok(null); //null表示正常返回状态码200
    }

    //校验登录
    @PostMapping("/loginVerification")
    public ResponseEntity loginVerification(@RequestBody Map map) {
        //调用map集合获取请求参数
        String phone = (String) map.get("phone");
        String code = (String) map.get("verificationCode");
        //调用userService完成用户登录
        Map retMap = userService.loginVerification(phone, code);
        //构造返回值
        return ResponseEntity.ok(retMap);
    }
}
